package jicheng;

import java.util.List;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.xx.jicheng.entity.Product;
import com.xx.jicheng.mapper.ProductMapper;

public class UpdateProductImg {

	public static void main(String[] args) {
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:spring.xml");
		ProductMapper mapper = context.getBean(ProductMapper.class);
		List<Product> list = mapper.findAll();
		for (Product p : list) {
			String img = p.getImg();
			if (img != null) {
				int idx = img.lastIndexOf("/");
				if (idx > -1) {
					p.setImg(img.substring(idx + 1));
				}
			} else {
				p.setImg("");
			}

			String detail = p.getDetail();
			if (detail != null) {
				int idx = detail.lastIndexOf("/");
				if (idx > -1) {
					p.setDetail(detail.substring(idx + 1));
				}
			} else {
				p.setDetail("");
			}
			mapper.updateImg(p);
		}
		context.close();
	}

}
